package utils;

import herd.Krill;

import java.util.ArrayList;
import java.util.List;

//TO DO
//CHange the manner of determining neighbours, its too slow
public class NeighboursDeterminator {
    private PositionMath positionMath = new PositionMath();

    public List<Krill> determinateNeighbours(List<Krill> herd, Krill krill){
        List<Krill> neighbours = new ArrayList<Krill>();
        double senseDistance = calculateSenseDistance(herd,krill);
        for(Krill other : herd){
            if(!other.equals(krill)){
                double distance = positionMath.determineDistance(krill.getPosition(), other.getPosition());
                if(distance <= senseDistance){
                    neighbours.add(other);
                }
            }
        }
        return neighbours;
    }

    private double calculateSenseDistance(List<Krill> herd, Krill krill){
        double distance = 0.0;
        for(Krill other : herd){
            distance += positionMath.determineDistance(krill.getPosition(),other.getPosition());
        }

        return distance/(5.0 * herd.size());
    }
}
